package com.ys.controller.api.amazonorder;

import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bo.vo.R;
import com.ys.dto.DtreeSqlDto;
import com.ys.dto.YsTreeDto;
import com.ys.entity.amazonorder.TbBaseinfoLmwh;
import com.ys.service.amazonorder.TbBaseinfoLmwhService;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.LayuiTableVoJA;

@Controller
@RequestMapping("/api/inter/tbBaseinfoLmwh")
public class ApiInterTbBaseinfoLmwhController {

    @Autowired
    private CommonApiService<TbBaseinfoLmwh> commonApiService;
    @Autowired
    private TbBaseinfoLmwhService tbBaseinfoLmwhService;
    
	@RequiresPermissions("tbBaseinfoLmwh:view")
    @RequestMapping("/search")
    @ResponseBody
    public LayuiTableVoJA search(@ModelAttribute TbBaseinfoLmwh cond, Long nodeId) {

        if (nodeId != null) {
            TbBaseinfoLmwh tbBaseinfoLmwh = new TbBaseinfoLmwh().setId(nodeId).queryFirst();
            cond.addLeftJoin("TB_BaseinfoLmwh AA on AA.id = A.pid")
                    .where("AA.NodeLft >= " + tbBaseinfoLmwh.getNodeLft())
                    .where("AA.NodeRgt <= " + tbBaseinfoLmwh.getNodeRgt());
        }
        return commonApiService.searchLay(cond);
    }

    @RequestMapping("/dtree")
    @ResponseBody
    public DtreeSqlDto dtree(){
        return tbBaseinfoLmwhService.dtree();
    }

    @RequestMapping("/ysTree")
    @ResponseBody
    public YsTreeDto ysTree(){
        return tbBaseinfoLmwhService.ysTree();
    }
    
    /**
     * 新增
     */
    @RequiresPermissions("tbBaseinfoLmwh:edit")
    @PostMapping("/add")
    @ResponseBody
    public R add(@RequestParam Map<String, Object> params) {
        return tbBaseinfoLmwhService.add(params);
    }

    /**
     * 修改
     */
    @RequiresPermissions("tbBaseinfoLmwh:edit")
    @PostMapping("/edit")
    @ResponseBody
    public R edit(@RequestParam Map<String, Object> params) {
        return tbBaseinfoLmwhService.edit(params);
    }

    /**
     * 删除
     */
    @RequiresPermissions("tbBaseinfoLmwh:delete")
    @PostMapping("/deleteTrue")
    @ResponseBody
    public R deleteTrue(String ids) {
        for (String idStr : ids.split(",")) {
            tbBaseinfoLmwhService.deleteTbBaseinfoLmwh(Long.parseLong(idStr));
        }
        return R.ok("删除成功!");
    }


    /**
     * 商品类目-弹出框信息查询
     */
    @RequestMapping("/searchForModal")
    @ResponseBody
    public LayuiTableVoJA searchByModelSelector(@ModelAttribute TbBaseinfoLmwh cond){
    	return tbBaseinfoLmwhService.searchLay(cond);
    }

}


